import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D



def draw_line():
    x = np.arange(1, 11)
    y = 2 * x + 5
    plt.title('matplotlib demo')
    plt.xlabel('x axis caption')
    plt.ylabel('y axis caption')
    # plt.plot(x,y)
    # 用圆点来显示，而不是用线
    plt.plot(x, y, "ob")
    plt.show()


def draw_sin():
    x = np.arange(0, 3 * np.pi, 0.1)
    y = np.sin(x)
    plt.title('draw sin line ')
    plt.plot(x, y)
    plt.show()


def draw_bar():
    x = [5, 8, 10]
    y = [12, 16, 6]
    x2 = [6, 9, 11]
    y2 = [6, 15, 7]
    plt.bar(x, y, align='center')
    plt.bar(x2, y2, color='y', align='center')
    plt.title('bar graph')
    plt.xlabel('x axis')
    plt.ylabel('y axis')
    plt.show()


def draw_hist():
    a = np.array([2, 3, 5, 7, 8, 55, 66, 22, 44, 66, 88, 99, 77])
    # 用于将传入数据按照区间段来进行统计个数，画出直方图
    plt.hist(a, bins=[0, 20, 40, 60, 80, 100], color='r')
    plt.title("histogram")
    plt.show()


def draw_scatter():
    n = 1024
    X = np.random.normal(0, 1, n)
    Y = np.random.normal(0, 1, n)
    T = np.arctan2(X, Y, )
    # 前两参数是相对于坐标原点的位置，后两个参数是指坐标轴的长度
    plt.axes([0.025, 0.025, 0.95, 0.95])
    # s为shape c为color alpha是透明度
    plt.scatter(X, Y, s=75, c=T, alpha=.5)
    # xlim为设置图像显示的在x轴的区域，ylim为在y轴的
    plt.xlim(-1.5, 1.5), plt.xticks([])
    plt.ylim(-1.5, 1.5), plt.yticks([])
    plt.show()


def draw_axes_3d():
    fig = plt.figure()
    ax = Axes3D(fig)
    X = np.arange(-4, 4, 0.25)
    Y = np.arange(-4, 4, 0.25)
    X, Y = np.meshgrid(X, Y)
    R = np.sqrt(X ** 2 + Y ** 2)
    Z = np.sin(R)

    ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.cm.hot)
    ax.contourf(X, Y, Z, zdir='z', offset=-2, cmap=plt.cm.hot)
    ax.set_zlim(-2, 2)
    plt.show()


draw_axes_3d()
